package com.mgface.zookeeper.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.imps.DefaultACLProvider;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.ZooKeeper;
/**
 * zkpaths提供一些简单的API来构建zonde的路径，递归创建，删除节点等
 * @author user
 *
 */
public class ZKPathsUse {
	static final String path = "/zkpaths";
	static CuratorFramework client = CuratorFrameworkFactory.builder().connectString("localhost:2181,localhost:2182,localhost:2183")
			.connectionTimeoutMs(20_000).sessionTimeoutMs(20_000)
	.retryPolicy(new ExponentialBackoffRetry(1_000, 3)).build();
	public static void main(String[] args) throws Exception {
		client.start();
		String ps = ZKPaths.fixForNamespace(path, "/zk1",true);
		System.out.println(ZKPaths.makePath(path, "/c1"));
		System.out.println(ZKPaths.getNodeFromPath(path));
		ZooKeeper zookeeper = client.getZookeeperClient().getZooKeeper();
		ZKPaths.mkdirs(zookeeper, ps, true, new DefaultACLProvider());
		System.out.println(zookeeper.getChildren(path, true));
	}

}
